/**
 * This file is part of Lineage II Client Data Parser.
 * 
 * Lineage II Client Data Parser is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.

 * Lineage II Client Data Parser is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with Lineage II Client Data Parser.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.l2emuproject.entity;

import net.l2emuproject.entity.base.DefaultEntity;

/**
 * @author Savormix
 *
 */
public final class SystemMessage extends DefaultEntity
{
	private static final String	UNDERSCORE		= "_";
	private static final String	DEFAULT_PREFIX	= "UNNAMED_";
	private static final String	FIELD_PREFIX	= "S";

	private final int			id;
	private final int			unk_0;
	private final String		cMsg;
	private final int			group;
	private final int			red;
	private final int			green;
	private final int			blue;
	private final int			alpha;
	private final String		sound;
	private final String		ref;
	private final int			unk_1_0;
	private final int			unk_1_1;
	private final int			unk_1_2;
	private final int			unk_1_3;
	private final int			unk_1_4;
	private final String		sMsg;
	private final String		type;
	// Deterministic
	private String				emptyFieldIds	= "";

	// Experimental

	/**
	 * Constructs a system message.
	 * @param id message ID
	 * @param unk_0 unknown
	 * @param cMsg Message shown in console
	 * @param group Message group
	 * @param red RGBA color
	 * @param green RGBA color
	 * @param blue RGBA color
	 * @param alpha RGBA transparency
	 * @param sound Sound played
	 * @param ref unknown
	 * @param unk_1_0 unknown
	 * @param unk_1_1 unknown
	 * @param unk_1_2 unknown
	 * @param unk_1_3 unknown
	 * @param unk_1_4 unknown
	 * @param sMsg Message shown on screen
	 * @param type Message type
	 */
	public SystemMessage(int id, int unk_0, String cMsg, int group, int red, int green, int blue, int alpha, String sound, String ref, int unk_1_0,
			int unk_1_1, int unk_1_2, int unk_1_3, int unk_1_4, String sMsg, String type)
	{
		this.id = id;
		this.unk_0 = unk_0;
		this.cMsg = cMsg;
		this.group = group;
		this.red = red;
		this.green = green;
		this.blue = blue;
		this.alpha = alpha;
		this.sound = sound;
		this.ref = ref;
		this.unk_1_0 = unk_1_0;
		this.unk_1_1 = unk_1_1;
		this.unk_1_2 = unk_1_2;
		this.unk_1_3 = unk_1_3;
		this.unk_1_4 = unk_1_4;
		this.sMsg = sMsg;
		this.type = type;
	}

	/**
	 * @return the id
	 */
	public final int getId()
	{
		return id;
	}

	/**
	 * @return the unk_0
	 */
	public final int getUnk_0()
	{
		return unk_0;
	}

	/**
	 * @return the message shown in console
	 */
	public final String getMessage()
	{
		return cMsg;
	}

	/**
	 * @return the group
	 */
	public final int getGroup()
	{
		return group;
	}

	/**
	 * @return the red
	 */
	public final int getRed()
	{
		return red;
	}

	/**
	 * @return the green
	 */
	public final int getGreen()
	{
		return green;
	}

	/**
	 * @return the blue
	 */
	public final int getBlue()
	{
		return blue;
	}

	/**
	 * @return the alpha
	 */
	public final int getAlpha()
	{
		return alpha;
	}

	/**
	 * @return the sound
	 */
	public final String getSound()
	{
		return sound;
	}

	/**
	 * @return the ref
	 */
	public final String getRef()
	{
		return ref;
	}

	/**
	 * @return the unk_1_0
	 */
	public final int getUnk_1_0()
	{
		return unk_1_0;
	}

	/**
	 * @return the unk_1_1
	 */
	public final int getUnk_1_1()
	{
		return unk_1_1;
	}

	/**
	 * @return the unk_1_2
	 */
	public final int getUnk_1_2()
	{
		return unk_1_2;
	}

	/**
	 * @return the unk_1_3
	 */
	public final int getUnk_1_3()
	{
		return unk_1_3;
	}

	/**
	 * @return the unk_1_4
	 */
	public final int getUnk_1_4()
	{
		return unk_1_4;
	}

	/**
	 * @return the message shown on screen
	 */
	public final String getScreenMessage()
	{
		return sMsg;
	}

	/**
	 * @return the type
	 */
	public final String getType()
	{
		return type;
	}

	/**
	 * @return the emptyFieldIds
	 */
	public final String getEmptyFieldIds()
	{
		return emptyFieldIds;
	}

	/**
	 * @param emptyFieldIds the emptyFieldIds to set
	 */
	public final void setEmptyFieldIds(String emptyFieldIds)
	{
		this.emptyFieldIds = emptyFieldIds;
	}

	/* (non-Javadoc)
	 * @see com.l2cdp.entity.IAnalysis#deterministicAnalysis()
	 */
	@Override
	public void deterministicAnalysis()
	{
		int current = getMessage().indexOf('$', 0);
		while (current != -1)
		{
			current++;
			try
			{
				String s = getMessage().substring(current, current + 2).trim();
				if (s.length() == 1)
					s = FIELD_PREFIX + s;
				emptyFieldIds += s.toUpperCase() + UNDERSCORE;
			}
			catch (StringIndexOutOfBoundsException e)
			{
				emptyFieldIds += (FIELD_PREFIX + getMessage().substring(current, current + 1) + UNDERSCORE);
				break;
			}
			current = getMessage().indexOf('$', current);
		}
	}

	/* (non-Javadoc)
	 * @see com.l2cdp.entity.IAnalysis#experimentalAnalysis()
	 */
	@Override
	public void experimentalAnalysis()
	{ /* Your ideas here */
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString()
	{
		return DEFAULT_PREFIX + getEmptyFieldIds() + getId();
	}
}
